# 2022-4-23 by Nasa
# 自建hash table 类


class HashTable:
    def __init__(self):
        self.keys = 11 * [None]
        self.values = 11 * [None]
        self.size = 11

    def __hash(self, word):
        h = word % self.size
        return h

    def put(self, key, value):
        hash_k = key % self.size
        hash_k = self.__hash(key)
        self.keys[hash_k] = key
        self.values[hash_k] = value

    def get(self, key):
        hash_k = key % self.size
        get_values = self.values[hash_k]
        return get_values

    def __str__(self):
        # return str(self.keys) + str(self.values)
        kv = ''
        for i in range(0, len(self.keys)):
            if self.keys[i] is not None:
                kv += str(self.keys[i]) + ':' + str(self.values[i]) + ' '
        return kv

    def __getitem__(self, key):
        return self.get(key)

    def __setitem__(self, key, value):
        n= self.__hash(key)
        self.keys[n]=key
        self.values[n]=value

if __name__ == '__main__':
    myhash = HashTable()
    myhash.put(0, 'zhang')
    myhash.put(26, 'zheng')
    myhash[2] = 'ma'
    print(myhash.keys, myhash.values)
    print(myhash.get(1))
    print('myhash:', myhash)
    print('---', myhash[26])